//
//  BlockTypeUtil.m
//  hexa
//
//  Created by kelly on 2014. 12. 31..
//  Copyright (c) 2014년 campmobile. All rights reserved.
//

#import "BlockTypeUtil.h"

@implementation BlockTypeUtil

+ (void)draw:(BlockType)blockType view:(BoardCell *)view i:(NSInteger)i j:(NSInteger)j
{
    [view setTag:[[NSString stringWithFormat:@"1%ld%ld", i, j] integerValue]];
    
    [BlockTypeUtil draw:blockType view:view];
}

+ (void)draw:(BlockType)blockType view:(BoardCell *)view
{
    //[view setClearsContextBeforeDrawing:YES];
    NSLog(@"tag = %ld, blockType = %ld", view.tag, blockType);
    if (view.blockType == blockType) {
        return;
    }
    
    [view setBlockType:blockType];
    if (blockType == BlockTypeNone) {
        [view.layer setHidden:YES];
        [view setNeedsDisplay];
        return;
    }
    
    [view.layer setHidden:NO];
    [view.layer setCornerRadius:5.0f];
    [view.layer setBorderColor:[UIColor lightGrayColor].CGColor];
    [view.layer setBorderWidth:SEPERATOR_WEIGHT];
    [view.layer setMasksToBounds:YES];
    [view setNeedsDisplay];
}

+ (NSString *)stringFromColor:(UIColor *)color
{
    const size_t totalComponents = CGColorGetNumberOfComponents(color.CGColor);
    const CGFloat *components = CGColorGetComponents(color.CGColor);
    return [NSString stringWithFormat:@"#%02X%02X%02X",
            (int)(255 * components[MIN(0, totalComponents - 2)]),
            (int)(255 * components[MIN(1, totalComponents - 2)]),
            (int)(255 * components[MIN(2, totalComponents - 2)])];
}

@end
